#ifndef __KERNELLIST_H__
#define __KERNELLIST_H__

typedef struct node
{
    struct node *prev;
    struct node *next;
}node, *list;

// 初始化
static list init_list(list head)
{
    head->next = head;
    head->prev = head;
}

// 头插法
static void list_add(list newnode, list prev, list next )
{
	next->prev = newnode;
	newnode->next = next;
	newnode->prev = prev;
	prev->next = newnode;
}

// 尾插法
static void list_add_tail(list head, list newnode)
{
    list_add(newnode, head->prev, head->next);
}

// 从头到尾遍历链表
#define list_for_each(ptr, head) for((ptr)=(head)->next; (ptr)!=(head); (ptr)=(ptr)->next)

// 从小结构体指针ptr，获得大结构体指针p
#define list_entry(ptr, type, member) \
            (type *) ( (char*)ptr - (long)(&((type*)0)->member) )

#endif
